package com.cpz.knife4j.controller.backend;

import com.cpz.knife4j.controller.DateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

/**
 * <h2>后端 API 基类</h2>
 * @author cpz
 * @since 2022/10/12
 */
@Validated
@RequestMapping("/backend")
public abstract class BackendBaseController {

    /**
     * 初始绑定
     *
     * @param binder
     */
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new DateEditor(true));
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    }
}
